import datetime
import os.path
import sys

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

#创建一个浏览器对象
class Driver:
    driver=""
    def __init__(self):
        options=webdriver.ChromeOptions ()
        self.driver=webdriver.Chrome(service=Service(ChromeDriverManager().install()),options=options)
        self.driver.implicitly_wait(3)
    def getScreenShot(self):
        #创建屏幕截图
        #图片文件名称：./2024-09-07-163300.png
        dirname=datetime.datetime.now().strftime("%Y-%m-%d")
        #判断dirname文件是否已经存在，若不存在则创建文件夹
        if not os.path.exists("E:/程序/auto_Test/BlogAutoTest/common/images/"+dirname):
            os.mkdir("E:/程序/auto_Test/BlogAutoTest/common/images/"+dirname)
        #2024-09-07-163300.png
        #图片路径:../images/调用方法-2024-09-07-163300.png
        # 图片路径:../images/LoginSucTest-2024-09-07-163300.png
        # 图片路径:../images/LoginFailTest-2024-09-07-163300.png
        filename=sys._getframe().f_back.f_code.co_name+"-"+datetime.datetime.now().strftime("%Y-%m-%d-%H%M%S")+".png"
        self.driver.save_screenshot("E:/程序/auto_Test/BlogAutoTest/common/images/"+dirname+"/"+filename)
        # self.driver.get_screenshot_as_file("E:\111.png")
BlogDriver=Driver()